﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ReworkManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ReworkManagement.ReworkReasonVMs
{
    public partial class ReworkReasonListVM : BasePagedListVM<ReworkReason_View, ReworkReasonSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ReworkReason_View>> InitGridHeader()
        {
            return new List<GridColumn<ReworkReason_View>>{
                
                this.MakeGridHeader(x => x.ReworkReason_ProductId).SetTitle(@Localizer["Page.适用产品"].Value),
                this.MakeGridHeader(x => x.ReworkReason_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ReworkReason_ReType).SetTitle(@Localizer["Page.返工类型"].Value),
                this.MakeGridHeader(x => x.ReworkReason_ReasonName).SetTitle(@Localizer["Page.原因名称"].Value),
                this.MakeGridHeader(x => x.ReworkReason_ReasonCode).SetTitle(@Localizer["Page.原因编码"].Value),
                this.MakeGridHeader(x => x.ReworkReason_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ReworkReason_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ReworkReason_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ReworkReason_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ReworkReason_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ReworkReason_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ReworkReason_View> GetSearchQuery()
        {
            var query = DC.Set<ReworkReason>()
                
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.ReTypeId, x=>x.ReTypeId)
                .CheckContain(Searcher.ReasonName, x=>x.ReasonName)
                .CheckContain(Searcher.ReasonCode, x=>x.ReasonCode)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ReworkReason_View
                {
				    ID = x.ID,
                    
                    ReworkReason_ProductId = x.ProductId,
                    ReworkReason_ProductName = x.ProductName,
                    ReworkReason_ReType = x.ReType.TenantCode,
                    ReworkReason_ReasonName = x.ReasonName,
                    ReworkReason_ReasonCode = x.ReasonCode,
                    ReworkReason_Active = x.Active,
                    ReworkReason_CreateTime = x.CreateTime,
                    ReworkReason_UpdateTime = x.UpdateTime,
                    ReworkReason_CreateBy = x.CreateBy,
                    ReworkReason_UpdateBy = x.UpdateBy,
                    ReworkReason_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ReworkReason_View: ReworkReason
    {
        
        public long? ReworkReason_ProductId { get; set; }
        public string ReworkReason_ProductName { get; set; }
        public string ReworkReason_ReType { get; set; }
        public string ReworkReason_ReasonName { get; set; }
        public string ReworkReason_ReasonCode { get; set; }
        public bool? ReworkReason_Active { get; set; }
        public DateTime? ReworkReason_CreateTime { get; set; }
        public DateTime? ReworkReason_UpdateTime { get; set; }
        public string ReworkReason_CreateBy { get; set; }
        public string ReworkReason_UpdateBy { get; set; }
        public bool ReworkReason_IsValid { get; set; }

    }

}